package com.workflow.engine.parser.utils;

import com.workflow.engine.core.flow.IStep;
import com.workflow.engine.core.flow.StepState;

import static com.workflow.engine.core.flow.Constants._FLOW_CONTINUE_FLAG;
import static com.workflow.engine.core.flow.Constants._FLOW_FINISHED_FLAG;
import static com.workflow.engine.core.flow.Constants._STEP_FAILURE_FLAG;
import static com.workflow.engine.core.flow.Constants._STEP_SUCCESS_FLAG;
import static com.workflow.engine.core.flow.Constants._STEP_SUCCESS_WITH_INFO_FLAG;

/**
 * Created by houjinxin on 2016/12/31.
 */
public class StepStateUtil {
    /**
     * 成功的步骤状态
     *
     * @param step
     * @return
     */
    public static StepState successfulStepState(IStep step) {
        return new StepState(step.getClass().getName(), _STEP_SUCCESS_FLAG, _FLOW_CONTINUE_FLAG);
    }

    /**
     * 带分支的步骤状态
     *
     * @param step
     * @param forkFlag
     * @return
     */
    public static StepState successfulStepState(IStep step, String forkFlag) {
        return new StepState(step.getClass().getName(), _STEP_SUCCESS_FLAG, _FLOW_CONTINUE_FLAG, forkFlag);
    }

    /**
     * 步骤执行成功但是需要返回信息(如车型列表)
     *
     * @param step
     * @param msgEnum
     * @return
     */
    public static StepState finishFlowWithStepInfo(IStep step, Object msgEnum) {
        return new StepState(step.getClass().getName(), _STEP_SUCCESS_WITH_INFO_FLAG, _FLOW_FINISHED_FLAG, null, msgEnum);
    }

    /**
     * 失败的步骤状态
     *
     * @param step
     * @return
     */
    public static StepState failureStepState(IStep step) {
        return new StepState(step.getClass().getName(), _STEP_FAILURE_FLAG, _FLOW_FINISHED_FLAG);
    }

    /**
     * 带异常信息的失败的步骤状态
     *
     * @param step
     * @return
     */
    public static StepState failureStepState(IStep step, Object msgEnum) {
        return new StepState(step.getClass().getName(), _STEP_FAILURE_FLAG, _FLOW_FINISHED_FLAG, null, msgEnum);
    }
}
